import {reqGetCategory1List,reqGetCategory2List,reqGetCategory3List} from "@/api/product/categroy"
const state = {
  category1Id: null,
  category2Id: null,
  category3Id: null,
  category1List:[],
  category2List:[],
  category3List:[],
};
const mutations = {
    SET_CATEGORY1LIST(state,payload){
        state.category1List = payload
    },
    SET_CATEGORY2LIST(state,payload){
        state.category2List = payload
    },
    SET_CATEGORY3LIST(state,payload){
        state.category3List = payload
    },
    SET_CATEGORY1ID(state,payload){
        state.category1Id = payload
    },
    SET_CATEGORY2ID(state,payload){
        state.category2Id = payload
    },
    SET_CATEGORY3ID(state,payload){
        state.category3Id = payload
    },
};
const actions = {
    //获取一级分类列表
    async getCategory1ListActions({commit}){
       const result = await reqGetCategory1List()
       commit("SET_CATEGORY1LIST",result)
    },
     //获取二级分类列表
     async getCategory2ListActions({commit}){
        const result = await reqGetCategory2List(state.category1Id)
        commit("SET_CATEGORY2LIST",result)
     },
      //获取三级分类列表
    async getCategory3ListActions({commit}){
        const result = await reqGetCategory3List(state.category2Id)
        commit("SET_CATEGORY3LIST",result)
     },
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
};
